package com.lyr.query.dynamic.core.utils;

// FieldValidator.java
public class FieldValidator {
    // 校验字段名合法性（防止SQL注入）
    public static void validateFieldName(String name) {
        if (!name.matches("[a-zA-Z0-9_.]+")) {
            throw new IllegalArgumentException("非法字段名或表别名: " + name);
        }
    }

    // 校验字段是否存在于实体类中（支持嵌套字段）
    public static void validateField(Class<?> entityClass, String fullFieldName) {
//        try {
//            String[] parts = fullFieldName.split("\\.");
//            Class<?> currentClass = entityClass;
//            for (String part : parts) {
//                Field field = currentClass.getDeclaredField(part);
//                currentClass = field.getType();
//            }
//        } catch (NoSuchFieldException e) {
//            throw new IllegalArgumentException("实体类中不存在字段: " + fullFieldName);
//        }
    }
}